/*    
 * Copyright (c) 2013 ISoftStone, Inc.
 * All right reserved.
 *
 * 文件名：      SpecialAccountBookItemServiceImpl.java
 * 作者:     Jacky Wang
 * 创建日期： 2013-7-30 下午04:21:49
 * 版本：           
 *
 */
package com.isoftstone.industry.aaa.core.service.assist.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.isoftstone.industry.persistance.bean.SpecialAccountBookItem;
import com.isoftstone.industry.aaa.core.dao.assist.SpecialAccountBookItemDao;
import com.isoftstone.industry.aaa.core.service.assist.ISpecialAccountBookItemService;
import com.isoftstone.modules.core.persistence.IGenericDao;
import com.isoftstone.modules.core.service.impl.GenericServiceImpl;
import com.isoftstone.modules.core.utils.DateUtils;

/**
 * @author jacky
 */
@Service
public class SpecialAccountBookItemServiceImpl extends GenericServiceImpl<SpecialAccountBookItem, String> implements ISpecialAccountBookItemService
{
	@Resource
	private SpecialAccountBookItemDao	spAcctBookItemDao;

	@Override
	public IGenericDao<SpecialAccountBookItem, String> getDao()
	{
		return spAcctBookItemDao;
	}

	@Override
	public List<SpecialAccountBookItem> findEffectGivenItemBySource(String acctBookId, String source, String sourceId, Date date)
	{
		return spAcctBookItemDao.findBySourceAndTypeAndAcctBookAndDateBetween(sourceId, source, SpecialAccountBookItem.Type.GIVEN, acctBookId, date);
	}

	@Override
	public List<SpecialAccountBookItem> findEffectPrepaidItemBySource(String acctBookId, String source, String sourceId, Date date)
	{
		return spAcctBookItemDao.findBySourceAndTypeAndAcctBookAndDateBetween(sourceId, source, SpecialAccountBookItem.Type.PREPAID, acctBookId, date);
	}

	@Override
	public SpecialAccountBookItem findGevinInstItem(String acctBookId, String sourceId, String source)
	{
		List<SpecialAccountBookItem> items = spAcctBookItemDao.findBySourceAndTypeAndAcctBook(sourceId,
				source, SpecialAccountBookItem.Type.GIVEN, acctBookId);
		SpecialAccountBookItem result = null;
		if (items.size() > 0)
		{
			result = items.get(0);
		}
		return result;
	}

	@Override
	public SpecialAccountBookItem findPrepaidInstItem(String acctBookId, String sourceId, String source)
	{
		List<SpecialAccountBookItem> items = spAcctBookItemDao.findBySourceAndTypeAndAcctBook(sourceId,
				source, SpecialAccountBookItem.Type.PREPAID, acctBookId);
		SpecialAccountBookItem result = null;
		if (items.size() > 0)
		{
			result = items.get(0);
		}
		return result;
	}

	@Override
	public void updateBalance(String id, double balance)
	{
		spAcctBookItemDao.updateBalance(id, balance, DateUtils.getCurrentTimestamp());
	}

	@Override
	public void updateBalance(String id, double balance, double freezeBalance)
	{
		spAcctBookItemDao.updateBalance(id, balance, freezeBalance, DateUtils.getCurrentTimestamp());
	}


}
